﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OstCollection.cs" company="">
//   
// </copyright>
// <summary>
//   The ost collection.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;
using System.Collections;
using System.ComponentModel;

namespace Systemathics.UserControls
{
    /// <summary>
    /// The ost collection.
    /// </summary>
    public class OstCollection : CollectionBase, ICustomTypeDescriptor
    {
        #region collection impl

        /// <summary>
        /// The this.
        /// </summary>
        /// <param name="index">
        /// The index.
        /// </param>
        public Ost this[int index]
        {
            get { return (Ost) List[index]; }
        }

        /// <summary>
        /// The add.
        /// </summary>
        /// <param name="emp">
        /// The emp.
        /// </param>
        public void Add(Ost emp)
        {
            if (!List.Contains(emp))
                List.Add(emp);
        }

        /// <summary>
        /// The remove.
        /// </summary>
        /// <param name="emp">
        /// The emp.
        /// </param>
        public void Remove(Ost emp)
        {
            List.Remove(emp);
        }

        #endregion

        #region ICustomTypeDescriptor impl

        /// <summary>
        /// The get class name.
        /// </summary>
        /// <returns>
        /// The get class name.
        /// </returns>
        public string GetClassName()
        {
            return TypeDescriptor.GetClassName(this, true);
        }

        /// <summary>
        /// The get attributes.
        /// </summary>
        /// <returns>
        /// </returns>
        public AttributeCollection GetAttributes()
        {
            return TypeDescriptor.GetAttributes(this, true);
        }

        /// <summary>
        /// The get component name.
        /// </summary>
        /// <returns>
        /// The get component name.
        /// </returns>
        public string GetComponentName()
        {
            return TypeDescriptor.GetComponentName(this, true);
        }

        /// <summary>
        /// The get converter.
        /// </summary>
        /// <returns>
        /// </returns>
        public TypeConverter GetConverter()
        {
            return TypeDescriptor.GetConverter(this, true);
        }

        /// <summary>
        /// The get default event.
        /// </summary>
        /// <returns>
        /// </returns>
        public EventDescriptor GetDefaultEvent()
        {
            return TypeDescriptor.GetDefaultEvent(this, true);
        }

        /// <summary>
        /// The get default property.
        /// </summary>
        /// <returns>
        /// </returns>
        public PropertyDescriptor GetDefaultProperty()
        {
            return TypeDescriptor.GetDefaultProperty(this, true);
        }

        /// <summary>
        /// The get editor.
        /// </summary>
        /// <param name="editorBaseType">
        /// The editor base type.
        /// </param>
        /// <returns>
        /// The get editor.
        /// </returns>
        public object GetEditor(Type editorBaseType)
        {
            return TypeDescriptor.GetEditor(this, editorBaseType, true);
        }

        /// <summary>
        /// The get events.
        /// </summary>
        /// <param name="attributes">
        /// The attributes.
        /// </param>
        /// <returns>
        /// </returns>
        public EventDescriptorCollection GetEvents(Attribute[] attributes)
        {
            return TypeDescriptor.GetEvents(this, attributes, true);
        }

        /// <summary>
        /// The get events.
        /// </summary>
        /// <returns>
        /// </returns>
        public EventDescriptorCollection GetEvents()
        {
            return TypeDescriptor.GetEvents(this, true);
        }

        /// <summary>
        /// The get property owner.
        /// </summary>
        /// <param name="pd">
        /// The pd.
        /// </param>
        /// <returns>
        /// The get property owner.
        /// </returns>
        public object GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }


        /// <summary>
        /// The get properties.
        /// </summary>
        /// <param name="attributes">
        /// The attributes.
        /// </param>
        /// <returns>
        /// </returns>
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            return GetProperties();
        }

        /// <summary>
        /// The get properties.
        /// </summary>
        /// <returns>
        /// </returns>
        public PropertyDescriptorCollection GetProperties()
        {
            // Create a collection object to hold property descriptors
            var pds = new PropertyDescriptorCollection(null);

            // Iterate the list of employees
            for (int i = 0; i < List.Count; i++)
            {
                // Create a property descriptor for the employee item and add to the property descriptor collection
                var pd = new OstCollectionPropertyDescriptor(this, i);
                pds.Add(pd);
            }

// return the property descriptor collection
            return pds;
        }

        #endregion
    }
}